package com.rybbaby.tss.tasks.core.task;

import com.rybbaby.tss.tasks.core.annotation.TaskClass;
import com.rybbaby.tss.tasks.core.annotation.TaskMethod;
import com.rybbaby.tss.tasks.core.task.service.ITssMemberAttendClassRecordService;
import com.rybbaby.tss.tasks.core.task.service.ITssMemberCheckAttendanceService;
import com.rybbaby.tss.tasks.core.task.service.ITssMemberPackageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
@TaskClass(remark = "考勤任务调度")
public class AttendanceTask extends BaseTask {

	@Autowired
	private ITssMemberCheckAttendanceService tssMemberCheckAttendanceService;
	@Autowired
	private ITssMemberAttendClassRecordService tssMemberAttendClassRecordService;
	@Autowired
	private ITssMemberPackageService tssMemberPackageService;


	/*@Scheduled(cron = "0/20 * * * * ?")*/
	@TaskMethod(remark = "考勤任务调度")
	public void attendance() {
		log("开始考勤扣课时...");
		// TODO ...
		try {
			//  查询亲子本日出勤记录
			List<Map<String, Object>> parentingAttendance = tssMemberCheckAttendanceService.attendance(1,1);
			//本日亲子出勤扣除课时
			boolean a = tssMemberPackageService.deductiveHours(parentingAttendance);
			System.out.println(a);
			if(parentingAttendance.size()>0){
				if(!a){
					log("本日亲子出勤操作失败!");
				}
			}

			//  查询亲子本日缺勤补课记录
			List<Map<String, Object>> parentsMakeUpClasses = tssMemberCheckAttendanceService.attendance(3,1);
			//本日亲子缺勤补课 课时修改
			boolean b = tssMemberPackageService.remediationClassHour(parentsMakeUpClasses);
			if(parentsMakeUpClasses.size()>0) {
				if (!b) {
					log("本日亲子缺勤补课操作失败!");
				}
			}
			//  查询过度过本日出勤记录
			List<Map<String, Object>> transitionAttendance = tssMemberCheckAttendanceService.attendance(1,2);
			//  本日过渡出勤扣除天数
			boolean c = tssMemberPackageService.transitionAttendance(transitionAttendance);
			if(transitionAttendance.size()>0) {
				if (!c) {
					log("本日过渡出勤操作失败!");
				}
			}
			//  查询本日过渡缺勤记录
			List<Map<String, Object>> absentDays = tssMemberCheckAttendanceService.attendance(2,2);
			//  本日过渡缺勤
			boolean d = tssMemberPackageService.absentDays(absentDays);
			if(absentDays.size()>0) {
				if (!d) {
					log("本日过渡缺勤操作失败!");
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		log("考勤成功!");
	}
}
